package com.infoDiffusion.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.infoDiffusion.bean.EarthquakeBean;
import com.infoDiffusion.bean.EmergencyBean;
import com.infoDiffusion.bean.HydroStatBean;
import com.infoDiffusion.bean.KnowledgeBean;
import com.infoDiffusion.bean.MaterialBean;
import com.infoDiffusion.bean.UserBean;
import com.infoDiffusion.bean.WeatherInfoBean;
import com.infoDiffusion.dao.AllEventDao;
import com.infoDiffusion.dao.EarthquakeStatDao;
import com.infoDiffusion.util.DateUtil;
import com.infoDiffusion.util.StringUtil;

@Service
@Transactional(propagation = Propagation.REQUIRED)
public class AllEventService {
	@Autowired
	private AllEventDao alldao;

	public List liste(EarthquakeBean ebean) {
		String hql = "from EarthquakeBean";
		return alldao.getList(hql);
	}
	public List listelike(String title) {
		String hql = "from EarthquakeBean e where e.referPosition like '%"+title+"%'";
		System.out.println(hql);
		return  alldao.getList(hql);
	}

	public List listem(EmergencyBean ebean) {
		String hql = "from EmergencyBean ORDER BY id DESC";
		return alldao.getList(hql);
	}
	public List listemlike(String title) {
		String hql = "from EmergencyBean where title like '%"+title+"%'";
		return alldao.getList(hql);
	}
	
	public List listw(WeatherInfoBean wbean) {
		String hql = "from WeatherInfoBean";
		return alldao.getList(hql);
	}
	public List listwlike(String city) {
		String hql = "from WeatherInfoBean w where w.city like '%"+city+"%'";
		return alldao.getList(hql);
	}
	
	public WeatherInfoBean listweather(WeatherInfoBean wbean) {
		String sql = "select * from  weatherinfo order by refresh_date DESC limit 1 ";
		List<Map<String, Object>> list = alldao.getSQLList(sql,null);
		List<WeatherInfoBean> li = new ArrayList<WeatherInfoBean>();
		String city = null;
		Date refresh_date = null;
		String weather_regime = null;
		String temprature = null;
		Integer wind_power = null;
		String dominat_wind = null;
		String pollution_power = null;
		WeatherInfoBean w = new WeatherInfoBean();
		for (Map<String, Object> map : list) {
			city = map.get("city").toString();
			System.out.println(city);
			refresh_date = DateUtil.parseDate(map.get("refresh_date").toString());
			weather_regime = map.get("weather_regime").toString();
			temprature = map.get("temprature").toString();
			wind_power = StringUtil.parstInt(map.get("wind_power").toString());
			dominat_wind = map.get("dominat_wind").toString();
			pollution_power = map.get("pollution_power").toString();
			w.setCity(city);
			w.setDominatWind(dominat_wind);
			w.setPollutionPower(pollution_power);
			w.setRefreshDate(refresh_date);
			w.setWindPower(wind_power);
			w.setWeatherRegime(weather_regime);
			w.setTemprature(temprature);
			li.add(w);
		}
		return w;
	}
	
	public List listk(KnowledgeBean kbean) {
		String hql = "from KnowledgeBean";
		return alldao.getList(hql);
	}
	
	public List listklike(String title) {
		String hql = "from KnowledgeBean k where k.title like'%"+title+"%'";
		return alldao.getList(hql);
	}
	public List listBasick(KnowledgeBean kbean) {
		String hql = "from KnowledgeBean k where k.knowType = '基础知识'";
		return alldao.getList(hql);
	}
	
	public List listLawk(KnowledgeBean kbean) {
		String hql = "from KnowledgeBean where knowType = '法制知识'";
		return alldao.getList(hql);
	}
	public List listPlank(KnowledgeBean kbean) {
		String hql = "from KnowledgeBean where knowType = '应急预案'";
		return alldao.getList(hql);
	}
	public List listFirstaidk(KnowledgeBean kbean) {
		String hql = "from KnowledgeBean where knowType = '应急自救'";
		return alldao.getList(hql);
	}
	
	public KnowledgeBean getById(int id) {
		return (KnowledgeBean) alldao.getById(KnowledgeBean.class, id);
	}
	
	public EmergencyBean getByIdEmergency(int id) {
		return (EmergencyBean) alldao.getById(EmergencyBean.class, id);
	}
	
	public List listh(HydroStatBean hbean) {
		String hql = "from HydroStatBean";
		return alldao.getList(hql);
	}
	
	public List listhlike(String name) {
		String hql = "from HydroStatBean h where h.name like '%"+name+"%'";
		return alldao.getList(hql);
	}
	public boolean adde(EarthquakeBean ebean) {
		return alldao.add(ebean);
	}
	public boolean addw(WeatherInfoBean wbean) {
		return alldao.add(wbean);
	}
	public boolean add(HydroStatBean hbean) {
		return alldao.add(hbean);
	}
	

}
